package com.termux.ui.ide.tab

import com.idea.editor.TextEditor
import com.idea.editor.lang.c.CLanguage
import org.apache.commons.io.FileUtils
import java.io.File

class EditTab(file: File) : FileTab(file) {

    override fun onSelected() {
        (contentView as TextEditor).run {
            setText(FileUtils.readFileToString(file, "utf-8"))
            setOnTextChangedListener { changed = true }
            setLanguage(CLanguage.getInstance())
        }
    }

    override fun save() {
        FileUtils.write(file, (contentView as TextEditor).text.toString(), "utf-8")
        changed = false
    }

    override fun onClose() {
    }

}